package Controller;

import Data.*;
import MyInterfaces.MassageType;
import Service.Main;
import Service.SendMassage;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.text.Text;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

import java.io.*;
import java.net.Socket;
import java.net.URL;
import java.nio.file.Files;
import java.time.LocalDate;
import java.util.Date;
import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PrivateInformation {

    @FXML
    private ResourceBundle resources;
    @FXML
    private Text emailnumber;
    @FXML
    private Label ensureLable;
    @FXML
    private Label newpasswordLable;
    @FXML
    private Label captchaLable;
    @FXML
    private Label changePasswordLable;
    @FXML
    private RadioButton man;
    @FXML
    private RadioButton woman;
    @FXML
    private URL location;

    @FXML
    private Button deletefriend;

    @FXML
    private TextField captcha;

    @FXML
    private Button summit_Button;

    @FXML
    private ToggleGroup sex;

    @FXML
    private PasswordField ensurepassword;

    @FXML
    private DatePicker birth;

    @FXML
    private ImageView avatar;

    @FXML
    private TextArea saying;

    @FXML
    private Button exit_Button;

    @FXML
    private PasswordField newpassword;

    @FXML
    private Button get_captcha;

    @FXML
    private TextField username;

    private static File file;
    private Socket socket;
    private Date predate=new Date();
    @FXML
    private Text userid;
    @FXML
    private Button handOverTheGroupOwner;
    @FXML
    private Button outpeople;
    @FXML
    private Button ridAdmin;

    @FXML
    private Button setAdmin;

    public void setSocket(Socket socket) {
        this.socket = socket;
    }

    public void lookFriend(PrivateInformationData Fdata)
    {
        System.out.println("look me");
        userid.setText(Fdata.getUserid());
        Image image=new Image(new ByteArrayInputStream(Fdata.getAvatar()));
        avatar.setImage(image);
        avatar.setOnMouseClicked(null);
        emailnumber.setText(Fdata.getEmailNumber());
        username.setText(Fdata.getUserNickName());
        username.setEditable(false);
        if(Fdata.getBirth()!=null)
        {
            birth.setValue(Fdata.getBirth().toLocalDate());
        }

        birth.setDisable(true);
        saying.setText(Fdata.getSaying());
        saying.setEditable(false);
        if(Fdata.getSex()!=null&&Fdata.getSex().equals("男"))
        {
            sex.selectToggle(man);
        }
        else if(Fdata.getSex()!=null&&Fdata.getSex().equals("女"))
        {
            sex.selectToggle(woman);
        }
        man.setDisable(true);
        woman.setDisable(true);
        deletefriend.setVisible(true);


        get_captcha.setVisible(false);
        ensurepassword.setVisible(false);
        exit_Button.setVisible(false);
        newpassword.setVisible(false);
        ensurepassword.setVisible(false);
        captcha.setVisible(false);
        summit_Button.setVisible(false);
        ensureLable.setVisible(false);
        newpasswordLable.setVisible(false);
        captchaLable.setVisible(false);
        changePasswordLable.setVisible(false);

        handOverTheGroupOwner.setVisible(false);
        handOverTheGroupOwner.setDisable(true);
        outpeople.setVisible(false);
        outpeople.setDisable(true);
        ridAdmin.setVisible(false);
        ridAdmin.setDisable(true);
        setAdmin.setVisible(false);
        setAdmin.setDisable(true);
    }

    public void setFriend(PrivateInformationData frienddata)
    {
        userid.setText(frienddata.getUserid());
        Image image=new Image(new ByteArrayInputStream(frienddata.getAvatar()));
        avatar.setImage(image);
        avatar.setOnMouseClicked(null);
        emailnumber.setText(frienddata.getEmailNumber());
        username.setText(frienddata.getUserNickName());
        username.setEditable(false);
        birth.setValue(frienddata.getBirth().toLocalDate());
        birth.setDisable(true);
        saying.setText(frienddata.getSaying());
        saying.setEditable(false);
        if(frienddata.getSex().equals("男"))
        {
            sex.selectToggle(man);
        }
        else
        {
            sex.selectToggle(woman);
        }
        man.setDisable(true);
        woman.setDisable(true);


        get_captcha.setVisible(false);
        ensurepassword.setVisible(false);
        exit_Button.setVisible(false);
        newpassword.setVisible(false);
        ensurepassword.setVisible(false);
        captcha.setVisible(false);
        summit_Button.setVisible(false);
        ensureLable.setVisible(false);
        newpasswordLable.setVisible(false);
        captchaLable.setVisible(false);
        changePasswordLable.setVisible(false);
        deletefriend.setVisible(true);
        deletefriend.setDisable(false);

        handOverTheGroupOwner.setVisible(false);
        handOverTheGroupOwner.setDisable(true);
        outpeople.setVisible(false);
        outpeople.setDisable(true);
        ridAdmin.setVisible(false);
        ridAdmin.setDisable(true);
        setAdmin.setVisible(false);
        setAdmin.setDisable(true);
    }



    public void changeInformation(PrivateInformationData mydata)
    {
        predate.setTime(predate.getTime()-60*1000);
        if(mydata.getAvatar()!=null)
        {
            Image image=new Image(new ByteArrayInputStream(mydata.getAvatar()));
            avatar.setImage(image);
            avatar.setPreserveRatio(false);
        }

        if(mydata.getEmailNumber()!=null)
            emailnumber.setText(mydata.getEmailNumber());
        if(mydata.getUserNickName()!=null&&!mydata.getUserNickName().equals(""))
             username.setText(mydata.getUserNickName());
        if(mydata.getSaying()!=null&&!mydata.getSaying().equals(""))
            saying.setText(mydata.getSaying());

        userid.setText(mydata.getUserid());

        if(mydata.getBirth()!=null)
        {
            birth.setValue(mydata.getBirth().toLocalDate());
        }
        else birth.setValue(LocalDate.now());
        if(mydata.getSex()==null)
        {
            sex.selectToggle(woman);
        }
        else if(mydata.getSex().equals("男"))
        {
            sex.selectToggle(man);
        }
        deletefriend.setVisible(false);
        deletefriend.setDisable(true);

        handOverTheGroupOwner.setVisible(false);
        handOverTheGroupOwner.setDisable(true);
        outpeople.setVisible(false);
        outpeople.setDisable(true);
        ridAdmin.setVisible(false);
        ridAdmin.setDisable(true);
        setAdmin.setVisible(false);
        setAdmin.setDisable(true);

    //    Main.AllContronller.getChatMainController().changeMydata(mydata);
    }
    @FXML
    void initialize() {
        predate.setTime(predate.getTime()-60*1000);

        file=null;

        assert captcha != null : "fx:id=\"captcha\" was not injected: check your FXML file 'Controller.PrivateInformation.fxml'.";
        assert summit_Button != null : "fx:id=\"summit_Button\" was not injected: check your FXML file 'Controller.PrivateInformation.fxml'.";
        assert sex != null : "fx:id=\"sex\" was not injected: check your FXML file 'Controller.PrivateInformation.fxml'.";
        assert ensurepassword != null : "fx:id=\"ensurepassword\" was not injected: check your FXML file 'Controller.PrivateInformation.fxml'.";
        assert birth != null : "fx:id=\"birth\" was not injected: check your FXML file 'Controller.PrivateInformation.fxml'.";
        assert avatar != null : "fx:id=\"avatar\" was not injected: check your FXML file 'Controller.PrivateInformation.fxml'.";
        assert saying != null : "fx:id=\"saying\" was not injected: check your FXML file 'Controller.PrivateInformation.fxml'.";
        assert exit_Button != null : "fx:id=\"exit_Button\" was not injected: check your FXML file 'Controller.PrivateInformation.fxml'.";
        assert newpassword != null : "fx:id=\"newpassword\" was not injected: check your FXML file 'Controller.PrivateInformation.fxml'.";
        assert get_captcha != null : "fx:id=\"get_captcha\" was not injected: check your FXML file 'Controller.PrivateInformation.fxml'.";
        assert username != null : "fx:id=\"username\" was not injected: check your FXML file 'Controller.PrivateInformation.fxml'.";

    }

    public void GetCaptchaAction(javafx.event.ActionEvent actionEvent) throws IOException {
        String emailPattern="^([A-Za-z0-9_\\-\\.])+\\@([A-Za-z0-9_\\-\\.])+\\.([A-Za-z]{2,4})$";
        Pattern p=Pattern.compile(emailPattern);
        Matcher m=p.matcher(emailnumber.getText());
        if(m.find())
        {
            System.out.println("邮箱可以的");
            Date nowdate=new Date();
            if((nowdate.getTime()-predate.getTime())< 60 * 1000)
            {
                Alert alert = new Alert(Alert.AlertType.INFORMATION);
                alert.setTitle("错误");
                alert.setHeaderText(null);
                alert.setContentText("一分钟内不可以重复点击获取验证码!");
                alert.showAndWait();
                return ;
            }
            //发送获得验证码的消息
            event massage=new event();
            massage.setType(MassageType.Get_Captcha);
            massage.setT(new String(emailnumber.getText()));

            new SendMassage().sendMassage(massage);

            predate=new Date();
            System.out.println("发送成功");

        }
        else
        {
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setTitle("错误");
            alert.setHeaderText(null);
            alert.setContentText("邮箱格式错误");
            alert.showAndWait();
            return ;
        }
    }

    public void SubmitAction(ActionEvent actionEvent) throws IOException {

        if (newpassword.getText().equals(ensurepassword.getText())) {
            //如果密码一致，需要正则表达式判断
            String pwdPattern ="^(?=.*\\d)(?=.*[a-zA-Z])(?=.*[^\\da-zA-Z\\s]).{8,16}$";
            Pattern p=Pattern.compile(pwdPattern);
            Matcher m=p.matcher(newpassword.getText());
            if(m.find())
            {
                //通过了正则表达式
                System.out.println("可以");
            }
            else
            {
                if(!(newpassword.getText().equals("")))
                {
                    System.out.println(newpassword.getText());
                    System.out.println(pwdPattern);
                    //没有通过
                    Alert alert = new Alert(Alert.AlertType.INFORMATION);
                    alert.setTitle("错误");
                    alert.setHeaderText(null);
                    alert.setContentText("密码强度不够，必须是8-16位，需要有字母，数字，和特殊字符^_^");
                    alert.showAndWait();
                    return ;
                }
            }
            System.out.println("密码一致");
        } else {
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setTitle("错误");
            alert.setHeaderText(null);
            alert.setContentText("密码俩次不一致");
            alert.showAndWait();
            System.out.println("密码不一致");
            return ;
        }

        String gender="女";
        if(sex!=null)
        {
            if(sex.getSelectedToggle().equals(man))
            {
                gender="男";
            }
        }
        else sex.selectToggle(woman);

        java.sql.Date date=null;
        if(birth.getValue()!=null)
        {
            date=java.sql.Date.valueOf(birth.getValue());
        }
        //发送修改信息的资料
        event massage=new event();
        //java.sql.Date sqlDate = java.sql.Date.valueOf(birth.getValue());
//        System.out.println(file.getAbsolutePath()+userid.getText());
        byte[] t=null;
        if(file!=null)
        {
            byte[] buffer = new byte[1024];
            t=new byte[(int) file.length()];
            InputStream is= Files.newInputStream(file.toPath());
            ByteArrayOutputStream bos=new ByteArrayOutputStream();
            int len;
            while((len=is.read(buffer))!=-1)
            {
                bos.write(buffer,0,len);
            }
            t=bos.toByteArray();
        }

        //    java.sql.Date.valueOf(birth.getValue())
        PrivateInformationData privateInformationData=new PrivateInformationData(t,username.getText(),gender,date,
                                                                                 saying.getText(),newpassword.getText(),userid.getText(),emailnumber.getText(),captcha.getText());
        String filename=null;
        if(file!=null)
        {
            filename=file.getName();
            int dotIndex=filename.lastIndexOf('.');
            if(dotIndex>0&&dotIndex<filename.length()-1)
            {
                privateInformationData.setSuffix_name(filename.substring(dotIndex+1));
                System.out.println(filename.substring(dotIndex+1));
            }
            else privateInformationData.setSuffix_name("");
        }

    //    privateInformationData.setSuffix_name(filename);
        massage.setT(privateInformationData);
        massage.setType(MassageType.Change_Information);
        new SendMassage().sendMassage(massage);
    }

    public void ExitAction(javafx.event.ActionEvent actionEvent) {
        Main.AllContronller.setPrivateInformationController(null);
        Stage stage = (Stage) exit_Button.getScene().getWindow();
        stage.close();
    }

    public void ChangeAvatar(MouseEvent mouseEvent) throws IOException {
        Stage stage=new Stage();
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle("选择头像");

        fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))
        );
        fileChooser.getExtensionFilters().addAll(
                new FileChooser.ExtensionFilter("All Images", "*.*"),
                new FileChooser.ExtensionFilter("JPG", "*.jpg"),
                new FileChooser.ExtensionFilter("GIF", "*.gif"),
                new FileChooser.ExtensionFilter("BMP", "*.bmp"),
                new FileChooser.ExtensionFilter("PNG", "*.png")
        );
        file= fileChooser.showOpenDialog(stage);

//        System.out.println(file.getAbsolutePath());
//        System.out.println(file.getName());

        if(file!=null) {
            Image image=new Image("file:"+file);
            avatar.setPreserveRatio(false);
            avatar.setImage(image);
            System.out.println(file);
        }

    }

    public void DeleteFriendAction(ActionEvent actionEvent) throws IOException {
        //删除好友
        event massage=new event();
        massage.setType(MassageType.Delete_Friend);
        //得到自己的信息和他人的信息
        ChatMain chatMain=Main.AllContronller.getChatMainController();
        PrivateInformationData mydata=chatMain.getMydata();
        ChatData chatData=new ChatData(null,null,mydata.getUserid(),userid.getText());
        massage.setT(chatData);

        new SendMassage().sendMassage(massage);

        Stage stage=(Stage) deletefriend.getScene().getWindow();
        stage.close();
    }

    private GroupData groupData;
    private GroupFriendData groupFriendData;

    public void setOwnerLookAdmin(GroupData groupData,GroupFriendData groupFriendData)
    {
        //群主看管理员
        this.groupData=groupData;
        this.groupFriendData=groupFriendData;
        System.out.println("此时是群主看管理员");
        userid.setText(groupFriendData.getId());
        Image image=new Image(new ByteArrayInputStream(groupFriendData.getAvatar()));
        avatar.setImage(image);
        avatar.setOnMouseClicked(null);
        emailnumber.setText(groupFriendData.getEmailNumber());
        username.setText(groupFriendData.getUserNickName());
        username.setEditable(false);
        if(groupFriendData.getBirth()!=null)
        {
            birth.setValue(groupFriendData.getBirth().toLocalDate());
        }

        birth.setDisable(true);
        saying.setText(groupFriendData.getSaying());
        saying.setEditable(false);
        if(groupFriendData.getSex()!=null&&groupFriendData.getSex().equals("男"))
        {
            sex.selectToggle(man);
        }
        else if(groupFriendData.getSex()!=null&&groupFriendData.getSex().equals("女"))
        {
            sex.selectToggle(woman);
        }
        man.setDisable(true);
        woman.setDisable(true);
        deletefriend.setVisible(false);
        deletefriend.setDisable(true);


        get_captcha.setVisible(false);
        ensurepassword.setVisible(false);
        exit_Button.setVisible(false);
        newpassword.setVisible(false);
        ensurepassword.setVisible(false);
        captcha.setVisible(false);
        summit_Button.setVisible(false);
        ensureLable.setVisible(false);
        newpasswordLable.setVisible(false);
        captchaLable.setVisible(false);
        changePasswordLable.setVisible(false);

        handOverTheGroupOwner.setVisible(true);
        handOverTheGroupOwner.setDisable(false);
        outpeople.setVisible(true);
        outpeople.setDisable(false);
        ridAdmin.setVisible(true);
        ridAdmin.setDisable(false);
        setAdmin.setVisible(false);
        setAdmin.setDisable(true);

    }

    public void setOwnerLookPeople(GroupData groupData,GroupFriendData groupFriendData)
    {
        //群主看群友
        this.groupData=groupData;
        this.groupFriendData=groupFriendData;
        System.out.println("此时是群主看群友");
        userid.setText(groupFriendData.getId());
        Image image=new Image(new ByteArrayInputStream(groupFriendData.getAvatar()));
        avatar.setImage(image);
        avatar.setOnMouseClicked(null);
        emailnumber.setText(groupFriendData.getEmailNumber());
        username.setText(groupFriendData.getUserNickName());
        username.setEditable(false);
        if(groupFriendData.getBirth()!=null)
        {
            birth.setValue(groupFriendData.getBirth().toLocalDate());
        }

        birth.setDisable(true);
        saying.setText(groupFriendData.getSaying());
        saying.setEditable(false);
        if(groupFriendData.getSex()!=null&&groupFriendData.getSex().equals("男"))
        {
            sex.selectToggle(man);
        }
        else if(groupFriendData.getSex()!=null&&groupFriendData.getSex().equals("女"))
        {
            sex.selectToggle(woman);
        }
        man.setDisable(true);
        woman.setDisable(true);
        deletefriend.setVisible(false);
        deletefriend.setDisable(true);

        get_captcha.setVisible(false);
        ensurepassword.setVisible(false);
        exit_Button.setVisible(false);
        newpassword.setVisible(false);
        ensurepassword.setVisible(false);
        captcha.setVisible(false);
        summit_Button.setVisible(false);
        ensureLable.setVisible(false);
        newpasswordLable.setVisible(false);
        captchaLable.setVisible(false);
        changePasswordLable.setVisible(false);

        handOverTheGroupOwner.setVisible(true);
        handOverTheGroupOwner.setDisable(false);
        outpeople.setVisible(true);
        outpeople.setDisable(false);
        ridAdmin.setVisible(false);
        ridAdmin.setDisable(true);
        setAdmin.setVisible(true);
        setAdmin.setDisable(false);

    }

    public void setAdminLookPeople(GroupData groupData,GroupFriendData groupFriendData)
    {
        //管理员看群友
        this.groupData=groupData;
        this.groupFriendData=groupFriendData;
        System.out.println("此时是管理员看群友");
        userid.setText(groupFriendData.getId());
        Image image=new Image(new ByteArrayInputStream(groupFriendData.getAvatar()));
        avatar.setImage(image);
        avatar.setOnMouseClicked(null);
        emailnumber.setText(groupFriendData.getEmailNumber());
        username.setText(groupFriendData.getUserNickName());
        username.setEditable(false);
        if(groupFriendData.getBirth()!=null)
        {
            birth.setValue(groupFriendData.getBirth().toLocalDate());
        }

        birth.setDisable(true);
        saying.setText(groupFriendData.getSaying());
        saying.setEditable(false);
        if(groupFriendData.getSex()!=null&&groupFriendData.getSex().equals("男"))
        {
            sex.selectToggle(man);
        }
        else if(groupFriendData.getSex()!=null&&groupFriendData.getSex().equals("女"))
        {
            sex.selectToggle(woman);
        }
        man.setDisable(true);
        woman.setDisable(true);
        deletefriend.setVisible(false);
        deletefriend.setDisable(true);

        get_captcha.setVisible(false);
        ensurepassword.setVisible(false);
        exit_Button.setVisible(false);
        newpassword.setVisible(false);
        ensurepassword.setVisible(false);
        captcha.setVisible(false);
        summit_Button.setVisible(false);
        ensureLable.setVisible(false);
        newpasswordLable.setVisible(false);
        captchaLable.setVisible(false);
        changePasswordLable.setVisible(false);

        handOverTheGroupOwner.setVisible(false);
        handOverTheGroupOwner.setDisable(true);
        outpeople.setVisible(true);
        outpeople.setDisable(false);
        ridAdmin.setVisible(false);
        ridAdmin.setDisable(true);
        setAdmin.setVisible(false);
        setAdmin.setDisable(true);

    }

    public void setUpPosition(GroupData groupData,GroupFriendData groupFriendData)
    {

        //往上看
        this.groupData=groupData;
        this.groupFriendData=groupFriendData;
        userid.setText(groupFriendData.getId());
        Image image=new Image(new ByteArrayInputStream(groupFriendData.getAvatar()));
        avatar.setImage(image);
        avatar.setOnMouseClicked(null);
        emailnumber.setText(groupFriendData.getEmailNumber());
        username.setText(groupFriendData.getUserNickName());
        username.setEditable(false);
        if(groupFriendData.getBirth()!=null)
        {
            birth.setValue(groupFriendData.getBirth().toLocalDate());
        }

        birth.setDisable(true);
        saying.setText(groupFriendData.getSaying());
        saying.setEditable(false);
        if(groupFriendData.getSex()!=null&&groupFriendData.getSex().equals("男"))
        {
            sex.selectToggle(man);
        }
        else if(groupFriendData.getSex()!=null&&groupFriendData.getSex().equals("女"))
        {
            sex.selectToggle(woman);
        }
        man.setDisable(true);
        woman.setDisable(true);
        deletefriend.setVisible(false);
        deletefriend.setDisable(true);

        get_captcha.setVisible(false);
        ensurepassword.setVisible(false);
        exit_Button.setVisible(false);
        newpassword.setVisible(false);
        ensurepassword.setVisible(false);
        captcha.setVisible(false);
        summit_Button.setVisible(false);
        ensureLable.setVisible(false);
        newpasswordLable.setVisible(false);
        captchaLable.setVisible(false);
        changePasswordLable.setVisible(false);

        handOverTheGroupOwner.setVisible(false);
        handOverTheGroupOwner.setDisable(true);
        outpeople.setVisible(false);
        outpeople.setDisable(true);
        ridAdmin.setVisible(false);
        ridAdmin.setDisable(true);
        setAdmin.setVisible(false);
        setAdmin.setDisable(true);

    }

    public void SetOtherAdmin(ActionEvent actionEvent) throws IOException {
        //把其他人设置成管理员,发送一个请求修改数据库
        event massage=new event();
        massage.setType(MassageType.Request_Set_Other_Admin);

        //这里，需要，发送者，接收者的消息，然后就是好友列表
        GroupOperationData groupOperationData=new GroupOperationData();
        groupOperationData.setSender(groupData.getId());
        GroupFriendData nowfrienddata=new GroupFriendData();
        groupOperationData.setReceiver(groupFriendData);

        ChatMain chatMain=Main.AllContronller.getChatMainController();
        groupOperationData.setFriendlist(groupData.getGroup_friend_list());

        massage.setT(groupOperationData);
        new SendMassage().sendMassage(massage);

        Stage stage=(Stage) setAdmin.getScene().getWindow();
        stage.close();

    }

    public void OutPeople(ActionEvent actionEvent) throws IOException {

        //删除群友
        event massage=new event();
        massage.setType(MassageType.Request_Delete_Group_People);

        GroupOperationData groupOperationData=new GroupOperationData();
        groupOperationData.setReceiver(groupFriendData);

        groupOperationData.setFriendlist(groupData.getGroup_friend_list());
        massage.setT(groupOperationData);

        new SendMassage().sendMassage(massage);

        Stage stage=(Stage)outpeople.getScene().getWindow();
        stage.close();
    }

    public void HandOverGroupOwner(ActionEvent actionEvent) throws IOException {
        //移交群主
        event massage=new event();
        massage.setType(MassageType.Request_Set_Other_Group_Owner);
        //这里，需要，发送者，接收者的消息，然后就是好友列表
        GroupOperationData groupOperationData=new GroupOperationData();
        groupOperationData.setSender(groupData.getId());
        GroupFriendData nowfrienddata=new GroupFriendData();
        groupOperationData.setReceiver(groupFriendData);

        ChatMain chatMain=Main.AllContronller.getChatMainController();
        groupOperationData.setFriendlist(groupData.getGroup_friend_list());

        massage.setT(groupOperationData);
        new SendMassage().sendMassage(massage);

        Stage stage=(Stage) handOverTheGroupOwner.getScene().getWindow();
        stage.close();
    }

    public void RidOutAdmin(ActionEvent actionEvent) throws IOException {
        //去掉管理员的身份
        event massage=new event();
        massage.setType(MassageType.Request_Get_Rid_Of_Admin);

        GroupOperationData groupOperationData=new GroupOperationData();
        groupOperationData.setSender(groupData.getId());
        GroupFriendData nowfrienddata=new GroupFriendData();
        groupOperationData.setReceiver(groupFriendData);

        ChatMain chatMain=Main.AllContronller.getChatMainController();
        groupOperationData.setFriendlist(groupData.getGroup_friend_list());

        massage.setT(groupOperationData);
        new SendMassage().sendMassage(massage);

        Stage stage=(Stage) setAdmin.getScene().getWindow();
        stage.close();

    }
}
